[flake8-simplify] Apply SIM113 when index variable is of type int#21395
[flake8-simplify] Apply SIM113 when index variable is of type int#21395ntBre merged 3 commits intoastral-sh:mainfrom
flake8-simplify] Apply SIM113 when index variable is of type int#21395Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| SIM113 | 3 | 3 | 0 | 0 | 0 |
ntBre
left a comment
There was a problem hiding this comment.
Thank you!
Would you mind making this a preview change? It seems to be in the spirit of the rule and also matches the upstream linter for this test case, but I see there are some ecosystem hits.
Preview will also be nice in case we want to iterate further by inferring the type of the argument, for example with is_int. I think ResolvedPythonType only handles literals and simple operations on them like 1 + 2 rather than using type annotations. (I'm not saying we need to or should do that, just an idea)
|
SIM113’s recommendation is only safe when the index variable’s initial value is a strict instance of |
|
Ah, thanks for the clarification! Disregard my last paragraph then, but I'd still lean toward making it a preview change. |
|
Thanks for the feedback! I updated the rule to be gated behind preview for strict instances of |
crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs
Outdated
Show resolved
Hide resolved
flake8-simplify] Apply SIM113 when index variable is type intflake8-simplify] Apply SIM113 when index variable is of type int
Summary
Fixes #21393
Now the rule checks if the index variable is initialized as an
inttype rather than only flagging if the index variable is initialized to0. I usedResolvedPythonTypeto check if the index variable is aninttype.Test Plan
Updated snapshot test for
SIM113.